import Vue from "vue";
import Vuex from "vuex";
import {
	login,
	logout
} from '@/api/user.js'

Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		isLogin: false
	},
	mutations: {
		CHANGE_LOGIN_STATUS(state, loginStatus) {
			state.isLogin = loginStatus
		}
	},
	actions: {
		async login({
			commit
		}, payload) {
			console.log(payload)
			try {
				let res = await login()
				commit('CHANGE_LOGIN_STATUS', true)
				return res
			} catch (err) {
				return err
			}
		},
		async logout({
			commit
		}) {
			try {
				let res = await logout()
				commit('CHANGE_LOGIN_STATUS', false)
				return res
			} catch (err) {
				return err
			}
		}
	},
});

export default store;
